﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};

	var planstatusData = Jxstar.findComboData('planstatus');
	var moneytypeData = Jxstar.findComboData('moneytype');
	var authtypeData = Jxstar.findComboData('authtype');
	var projectjdData = Jxstar.findComboData('projectjd');
	var baotypeData = Jxstar.findComboData('baotype');
	var yesnoData = Jxstar.findComboData('yesno');
	var plantype2Data = Jxstar.findComboData('plantype2');
	var planyearData = Jxstar.findComboData('planyear');
	var plantypeData = Jxstar.findComboData('plantype');

	var cols = [
	{col:{header:'计划状态', width:76, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: planstatusData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: planstatusData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < planstatusData.length; i++) {
				if (planstatusData[i][0] == value)
					return planstatusData[i][1];
			}
		}}, field:{name:'money_plan__plan_status',type:'string'}},
	{col:{header:'计划编号', width:113, sortable:true}, field:{name:'money_plan__plan_code',type:'string'}},
	{col:{header:'项目名称', width:195, sortable:true}, field:{name:'money_plan__plan_name',type:'string'}},
	{col:{header:'项目类别', width:113, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: moneytypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false, allowBlank:false,
			value: moneytypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < moneytypeData.length; i++) {
				if (moneytypeData[i][0] == value)
					return moneytypeData[i][1];
			}
		}}, field:{name:'money_plan__money_type',type:'string'}},
	{col:{header:'预计总投资(万元)', width:119, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'money_plan__plan_money',type:'float'}},
	{col:{header:'当年预计投资(万元)', width:122, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'money_plan__year_money',type:'float'}},
	{col:{header:'授权形式', width:77, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: authtypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: authtypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < authtypeData.length; i++) {
				if (authtypeData[i][0] == value)
					return authtypeData[i][1];
			}
		}}, field:{name:'money_plan__auth_type',type:'string'}},
	{col:{header:'主管部门', width:100, sortable:true}, field:{name:'money_plan__done_deptname',type:'string'}},
	{col:{header:'合同金额(万元)', width:100, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'money_plan__money_contract',type:'float'}},
	{col:{header:'已付款金额(万元)', width:120, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'money_plan__money_pay',type:'float'}},
	{col:{header:'立项批复文号', width:100, sortable:true}, field:{name:'money_plan__project_fileno',type:'string'}},
	{col:{header:'当前形象进度', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: projectjdData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: projectjdData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < projectjdData.length; i++) {
				if (projectjdData[i][0] == value)
					return projectjdData[i][1];
			}
		}}, field:{name:'money_plan__project_process',type:'string'}},
	{col:{header:'计划包属性', width:70, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: baotypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: baotypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < baotypeData.length; i++) {
				if (baotypeData[i][0] == value)
					return baotypeData[i][1];
			}
		}}, field:{name:'money_plan__bao_type',type:'string'}},
	{col:{header:'父计划编号', width:90, sortable:true}, field:{name:'money_plan__plan_parentcode',type:'string'}},
	{col:{header:'是否结转', width:62, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: yesnoData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: yesnoData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < yesnoData.length; i++) {
				if (yesnoData[i][0] == value)
					return yesnoData[i][1];
			}
		}}, field:{name:'money_plan__is_turn',type:'string'}},
	{col:{header:'是否上报国家局', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: yesnoData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: yesnoData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < yesnoData.length; i++) {
				if (yesnoData[i][0] == value)
					return yesnoData[i][1];
			}
		}}, field:{name:'money_plan__up_comp',type:'string'}},
	{col:{header:'国家局项目类别', width:110, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: plantype2Data
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: plantype2Data[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < plantype2Data.length; i++) {
				if (plantype2Data[i][0] == value)
					return plantype2Data[i][1];
			}
		}}, field:{name:'money_plan__money_type2',type:'string'}},
	{col:{header:'预算年度', width:67, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: planyearData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: planyearData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < planyearData.length; i++) {
				if (planyearData[i][0] == value)
					return planyearData[i][1];
			}
		}}, field:{name:'money_plan__plan_year',type:'string'}},
	{col:{header:'申报日期', width:100, sortable:true, hidden:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'money_plan__plan_date',type:'date'}},
	{col:{header:'申报人', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_user',type:'string'}},
	{col:{header:'主要内容与申请理由', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_desc',type:'string'}},
	{col:{header:'备注', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_memo',type:'string'}},
	{col:{header:'主键', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_id',type:'string'}},
	{col:{header:'申报人ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_userid',type:'string'}},
	{col:{header:'计划类型', width:69, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: plantypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: plantypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < plantypeData.length; i++) {
				if (plantypeData[i][0] == value)
					return plantypeData[i][1];
			}
		}}, field:{name:'money_plan__plan_type',type:'string'}},
	{col:{header:'立项批复金额(万元)', width:100, sortable:true, hidden:true, renderer:JxUtil.formatNumber(6)}, field:{name:'money_plan__project_money',type:'float'}},
	{col:{header:'主管部门ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__done_deptid',type:'string'}},
	{col:{header:'立项批复日期', width:100, sortable:true, hidden:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'money_plan__project_checkdate',type:'date'}},
	{col:{header:'申报部门', width:100, sortable:true, hidden:true}, field:{name:'money_plan__dept_name',type:'string'}},
	{col:{header:'申报部门ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__dept_id',type:'string'}}
	];
	
	config.param = {
		cols: cols,
		sorts: null,
		hasQuery: '1',
		isedit: '0',
		isshow: '0',
		funid: 'money_select'
	};
	
	config.eventcfg = {
		mybao: function(){
			var records = this.grid.getSelectionModel().getSelections();
			if (!JxUtil.selected(records)) return;
			
			var self = this;
			var hdcall = function() {
				//取选择记录的主键值
				var params = 'funid='+ self.define.nodeid;
				for (var i = 0; i < records.length; i++) {
					params += '&keyid=' + records[i].get(self.define.pkcol);
				}

				var parentid = self.grid.destParentId;
				//设置请求的参数
				params += '&pagetype=selgrid&eventcode=mybao&parentId='+parentid;

				//执行处理的内容
				var endcall = function(data) {
					//重新加载数据
					self.grid.getStore().reload();
					
					//刷新目标表格
					var destGrid = self.grid.destGrid;
					if (destGrid != null) {
						destGrid.getStore().reload();
					}
				};

				//发送请求
				Request.postRequest(params, endcall);
			};
			
			Ext.Msg.confirm(jx.base.hint, '将对选择的投资计划进行合并实施，确定吗？', function(btn) {
				if (btn == 'yes') hdcall();
			});
		},
		
		imPlan: function(){
			var records = this.grid.getSelectionModel().getSelections();
			if (!JxUtil.selected(records)) return;
			
			var planids = '';
			for (var i = 0; i < records.length; i++) {
				var planid = records[i].get('money_plan__plan_id');
				planids += '&keyid=' + planid ;
			}
			
			var params = 'funid=money_select' + planids; 
			params += '&pagetype=grid&eventcode=imPlan';
			
			var self = this;
			var endcall = function(data) {
				//重新加载数据
				self.grid.getStore().reload();
				
				//刷新目标表格
				var destGrid = self.grid.destGrid;
				if (destGrid != null) {
					destGrid.getStore().reload();
				}	
			};

			//发送请求
			Request.postRequest(params, endcall);
		}
	};
		
	return new Jxstar.GridNode(config);
}